PersistedName

@Target(allowedTargets = [AnnotationTarget.PROPERTY])
annotation class PersistedName(name: String)

Annotation mapping a Kotlin field name to the field name persisted in the Realm.

This is useful when opening the Realm across different SDKs where code style conventions might differ.

Queries can be made using either of the names:

// Class with field using `@PersistedName`
class Example : RealmObject {
@PersistedName("myPersistedName") // or: @PersistedName(name = "myPersistedName")
var myKotlinName = "My value"
}

// Query by Kotlin name
realm.query<Example>("myKotlinName = $0", "My value")
.first()
.find()?
.myKotlinName

// Query by persisted name
realm.query<Example>("myPersistedName = $0", "My value")
.first()
.find()?
.myKotlinName

Constructors

PersistedName
Link copied to clipboard
fun PersistedName(name: String)

Properties

name
Link copied to clipboard
val name: String